<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page pageEncoding="UTF-8"%>
<%
    // 如果已经登录，跳转到首页
    if (session.getAttribute("user") != null) {
        response.sendRedirect(request.getContextPath() + "/index.jsp");
        return;
    }
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
    <link rel="stylesheet" href="<%= request.getContextPath() %>/assets/css/styles.css">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="header-nav">
        <div class="nav-container">
            <a href="<%= request.getContextPath() %>/index.jsp" class="nav-brand">购物网</a>
            
            <ul class="nav-links">
                <li><a href="<%= request.getContextPath() %>/index.jsp">首页</a></li>
                <li><a href="<%= request.getContextPath() %>/products/list.jsp">商品浏览</a></li>
                <li><a href="<%= request.getContextPath() %>/cart/view/cart.jsp">购物车</a></li>
            </ul>
            
            <div class="user-actions">
                <a href="<%= request.getContextPath() %>/auth/login.jsp" class="btn btn-outline">登录</a>
                <a href="<%= request.getContextPath() %>/auth/register.jsp" class="btn" style="margin-left: 10px;">注册</a>
            </div>
        </div>
    </nav>
    
    <div class="container">
        <div class="page-title">
            <h1>用户注册</h1>
        </div>
        
        <% if (request.getParameter("error") != null) { %>
            <div class="alert alert-error">
                <%= request.getParameter("error") %>
            </div>
        <% } %>
        
        <div class="card">
            <div class="card-body">
                <form action="register_action.jsp" method="post">
                    <div class="form-group">
                        <label for="username">用户名:</label>
                        <input type="text" id="username" name="username" class="form-control" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="realname">真实姓名:</label>
                        <input type="text" id="realname" name="realname" class="form-control">
                    </div>
                    
                    <div class="form-group">
                        <label for="password">密码:</label>
                        <input type="password" id="password" name="password" class="form-control" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="confirm_password">确认密码:</label>
                        <input type="password" id="confirm_password" name="confirm_password" class="form-control" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="email">邮箱:</label>
                        <input type="email" id="email" name="email" class="form-control" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="phone">电话:</label>
                        <input type="text" id="phone" name="phone" class="form-control">
                    </div>
                    
                    <div class="form-group">
                        <input type="submit" value="注册" class="btn btn-success" style="width: 100%; padding: 0.75rem; font-size: 1.1rem;">
                    </div>
                </form>
            </div>
        </div>
        
        <div style="text-align: center; margin-top: 1.5rem;">
            <p>已有账户? <a href="login.jsp">立即登录</a></p>
        </div>
    </div>
</body>
</html>